//
//  PictureTableViewCell.m
//  QT
//
//  Created by 甘世清 on 2024/10/23.
//

#import "PictureTableViewCell.h"

@implementation PictureTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)SQ_Style:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    
    [self.contentView addSubview:self.pictureImageView];
    [self.pictureImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 12, 10, 12));
    }];
    [self.contentView addSubview:self.visualEffectView];
    [self.visualEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.pictureImageView);
    }];
    [self.contentView addSubview:self.headerView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.messageLabel];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(40);
            make.left.top.equalTo(self.pictureImageView).offset(12);
    }];
   
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView).offset(2);
        make.left.equalTo(self.headerView.mas_right).offset(10);
        make.height.mas_equalTo(20);
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.headerView.mas_bottom).offset(-2);
        make.left.equalTo(self.headerView.mas_right).offset(10);
        make.height.mas_equalTo(20);
    }];
    
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView.mas_right).offset(10);
        make.top.equalTo(self.timeLabel.mas_bottom).offset(2);
        make.right.equalTo(self.pictureImageView.mas_right).offset(-10);
    }];
  
}
- (void)setModel:(PictureModel *)model{
    _model = model;
    [self.headerView.headerImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"2")];
    self.nameLabel.text = model.name;
    self.timeLabel.text = model.createTime;
    self.messageLabel.text = model.content;
    [self.pictureImageView sd_setImageWithURL:SQURLImage(model.imgs) placeholderImage:SQGetImage(@"1")];
    [self.contentView layoutIfNeeded];
   
}

- (HeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HeaderView alloc]init];
        _headerView.layer.cornerRadius = 20;
        _headerView.layer.masksToBounds = YES;
        _headerView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _headerView;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = SQColor333333;
        _nameLabel.font = FONT_MEDIUM(16);
    }
    return _nameLabel;
}
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.textColor = SQColor666666;
        _timeLabel.font = FONT_REGULAR(12);
    }
    return _timeLabel;
}
- (UIImageView *)pictureImageView{
    if (!_pictureImageView) {
        _pictureImageView = [[UIImageView alloc]init];
        _pictureImageView.contentMode = UIViewContentModeScaleAspectFill;
        _pictureImageView.clipsToBounds = YES;
        _pictureImageView.layer.cornerRadius = 10;
        _pictureImageView.layer.masksToBounds = YES;
    }
    return _pictureImageView;
}

- (UIVisualEffectView *)visualEffectView{
    if (!_visualEffectView) {
        UIBlurEffect * blureffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        _visualEffectView = [[UIVisualEffectView alloc]initWithEffect:blureffect];
        _visualEffectView.layer.cornerRadius = 10;
        _visualEffectView.layer.masksToBounds = YES;
    }
    return _visualEffectView;
}

- (UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.font = FONT_MEDIUM(12);
        _messageLabel.textColor = SQColor333333;
        _messageLabel.backgroundColor = UIColor.clearColor;
        _messageLabel.numberOfLines = 0;
    }
    return _messageLabel;
}
@end
